package com.zhx.learn.actuator.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;


/**
 * describe:
 *
 * @author zhanghaixuan
 * @date 2018/09/13
 **/
@Component
public class RuntimeFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("time filter init");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("time filter start");
        long startTime = System.currentTimeMillis();

        chain.doFilter(request, response);

        long endTime = System.currentTimeMillis();
        System.out.println("time filter consume " + (endTime - startTime) + " ms");
        System.out.println("time filter end");
    }

    @Override
    public void destroy() {
        System.out.println("time filter init");
    }
}
